Imports System.IO
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

#Region "CampaignerGameDataB"
'Public Class CampaignerGameDataB

'    Public Enum ModeratorFlag
'        SealedGame = 0
'        ModeratorReady = 1       '// does not HAVE to use a moderator for this campaign
'        ModeratorRequired = 2
'    End Enum

'    Public Enum ChitDetectionLevel
'        UnaccountedDL = 0
'        UndetectedDL = 1
'        DetectedDL = 2
'        SightedDL = 4
'        IdentifiedDL = 8
'        KnownDL = 12
'    End Enum

'    ' this class is the base for a game, its properties and collections define all elements in the campaign
'    Private mvarDemo As Boolean
'    Private mvarGameName As String
'    Private mvarVersion As String
'    Private mvarTheaterMapFilename As String = "none"
'    Private mvarTheaterMapScale As String = "1:1"
'    Private mvarTurn As Int16
'    Private mvarTurnLength As TurnLength_cgd
'    Private mvarMaxTurns As Int16
'    Private mvarUsesZOC As Boolean = False
'    Private mvarSystemValues As New Hashtable
'    Private m_Moderator As ModeratorFlag = ModeratorFlag.ModeratorReady
'    Private m_ModeratorPassword As String = "parsons"
'    Private m_ElManager As New ElementManager    ' handles specific elements defined in this game.
'    Private m_ReinforcementRange As Int16 = 50
'    Private m_AverageUnitMaxPV As Int32
'    Private m_AverageObjectiveMaxPV As Int32
'    Private m_MaxPointValueDeployed As Int32
'    Private m_UseElementsForPointValues As Boolean = False ' if this is set to true, then element cost will determine a unit's PV
'    Private m_UseElementsForMoveSpeed As Boolean = False
'    Private m_UseElementsForMoveClass As Boolean = False
'    Private m_UseElementsForLOSValues As Boolean = False
'    Private m_AllowReinforcements As Boolean = True   ' whether the units within reinforcement range are used
'    Private m_AllowPlayerManageChits As Boolean = False
'    Private m_GenericBoundaries As New GenericBoundaries
'    Private m_AreaObjectives As New GenericBoundaries
'    Private m_ExtendedProperties As New GenericProperties
'    Private m_OrderOfBattle As New Units
'    Private m_CampaignDescription As String
'    Private m_Orders As New OrderTypes2

'    Private m_Faction_g As New Factions
'    Private m_RuleTypes_g As New RuleTypes
'    Private m_Rules_g As New Rules
'    Private m_ResourceTypes_g As New ResourceTypes
'    Private m_Resources_g As New Resources
'    Private m_Messages_g As New Messages
'    Private m_DeploymentZones_g As New DeploymentZones
'    Private m_Battles_g As New Battles
'    Private m_Diplomacy_g As New Diplomacy
'    Private m_MapLabels_g As New MapLabels


'    Private m_AllChits As New Hashtable(45)        ' this holds all instances of objectives, units and tokens (NOT types)
'    Private m_ObjectiveTypes As New Hashtable(10)
'    Private m_UnitTypes As New Hashtable(10)
'    Private m_TokenTypes As New Hashtable(10)
'    Private m_selectedFaction As Faction
'    Private m_selectedPlayer As Player
'    Private m_SubObjectiveMaps As New SubObjectiveMaps
'    Private m_Players As New Hashtable(2)
'    Private m_LogEvents As New Hashtable(10)

'#Region "Hashtable Key Constants"
'    ' four letter key combinations for hashtable lookups, in case I decide to use them.
'    Public Const CGDKEY_OBJECTIVETYPE As String = "OBJT"
'    Public Const CDGKEY_RESOURCETYPE As String = "REST"
'    Public Const CDGKEY_RULETYPE As String = "RULT"
'    Public Const CDGKEY_UNITTYPE As String = "UNTT"
'    Public Const CDGKEY_TOKENTYPE As String = "TOKT"

'    Public Const CDGKEY_FACTION As String = "FACT"
'    Public Const CDGKEY_PLAYER As String = "PLAY"

'    Public Const CDGKEY_OBJECTIVE As String = "OBJE"
'    Public Const CDGKEY_RESOURCE As String = "RESO"
'    Public Const CDGKEY_RULE As String = "RULE"
'    Public Const CDGKEY_UNIT As String = "UNIT"
'    Public Const CDGKEY_TOKEN As String = "TOKN"
'    Public Const CDGKEY_ASSIGNEDRULE As String = "ASRL"

'    Public Const CDGKEY_ORDER As String = "ORDE"
'    Public Const CDGKEY_ORDERTYPE As String = "ORDT"

'    Public Const CDGKEY_BATTLE As String = "BATT"

'    Public Const CDGKEY_CHITTYPE As String = "CHTT" ' generic chit... there shouldn't be many of these.
'    Public Const CGDKEY_GROUNDCHITTYPE As String = "GCHT"  ' this is the main type that objective types, unit types and token types derive from.

'    ' icon IDs for determining the correct display icon
'    Public Const CDGDIP_OWNER As String = "Owner"
'    Public Const CDGDIP_SAMEFACTION As String = "SameFaction"
'    Public Const CDGDIP_ALLIED As String = "Allied"
'    Public Const CDGDIP_NEUTRAL As String = "Neutral"
'    Public Const CDGDIP_ENEMY As String = "Enemy"
'#End Region


'#Region "Properties"

'    Public Property OrderTypes() As OrderTypes2
'        Get
'            Return m_Orders
'        End Get
'        Set(ByVal Value As OrderTypes2)
'            m_Orders = Value
'        End Set
'    End Property


'    Public Property CampaignDescription() As String
'        Get
'            Return m_CampaignDescription
'        End Get
'        Set(ByVal Value As String)
'            m_CampaignDescription = Value
'        End Set
'    End Property

'    Public Property OrderOfBattle() As Units
'        Get
'            Return m_OrderOfBattle
'        End Get
'        Set(ByVal Value As Units)
'            m_OrderOfBattle = Value
'        End Set
'    End Property

'    Public Property Boundaries() As GenericBoundaries
'        Get
'            Return m_GenericBoundaries
'        End Get
'        Set(ByVal Value As GenericBoundaries)
'            m_GenericBoundaries = Value
'        End Set
'    End Property

'    Public Property AreaObjectives() As GenericBoundaries
'        Get
'            Return m_AreaObjectives
'        End Get
'        Set(ByVal Value As GenericBoundaries)
'            m_AreaObjectives = Value
'        End Set
'    End Property

'    Public Property ExtendedProperties() As GenericProperties
'        Get
'            Return m_ExtendedProperties
'        End Get
'        Set(ByVal Value As GenericProperties)
'            m_ExtendedProperties = Value
'        End Set
'    End Property

'    Public Property AllowReinforcements() As Boolean
'        Get
'            Return m_AllowReinforcements
'        End Get
'        Set(ByVal Value As Boolean)
'            m_AllowReinforcements = Value
'        End Set
'    End Property

'    Public Property UseElementsForPointValue() As Boolean
'        Get
'            Return m_UseElementsForPointValues
'        End Get
'        Set(ByVal Value As Boolean)
'            m_UseElementsForPointValues = Value
'        End Set
'    End Property

'    Public Property UseElementsForMoveSpeed() As Boolean
'        Get
'            Return m_UseElementsForMoveSpeed
'        End Get
'        Set(ByVal Value As Boolean)
'            m_UseElementsForMoveSpeed = Value
'        End Set
'    End Property

'    Public Property UseElementsForMoveClass() As Boolean
'        Get
'            Return m_UseElementsForMoveClass
'        End Get
'        Set(ByVal Value As Boolean)
'            m_UseElementsForMoveClass = Value
'        End Set
'    End Property

'    Public Property UseElementsForLOSValues() As Boolean
'        Get
'            Return m_UseElementsForLOSValues
'        End Get
'        Set(ByVal Value As Boolean)
'            m_UseElementsForLOSValues = Value
'        End Set
'    End Property

'    Public Property AllowPlayerManageChits() As Boolean
'        Get
'            Return m_AllowPlayerManageChits
'        End Get
'        Set(ByVal Value As Boolean)
'            m_AllowPlayerManageChits = Value
'        End Set
'    End Property

'    Public Property ElementMan() As ElementManager
'        Get
'            Return m_ElManager
'        End Get
'        Set(ByVal Value As ElementManager)
'            m_ElManager = Value
'        End Set
'    End Property

'    Public Function ReturnPlayerKeyWithID(ByVal id As Int64) As String
'        Dim playkey As String
'        Dim play As Player

'        For Each playkey In m_Players.Keys
'            play = m_Players.Item(playkey)
'            If play.PlayerID = id Then
'                Return playkey
'            End If
'        Next

'        ' if we can't find the player with this id, raise an error
'        Throw New ArgumentOutOfRangeException

'    End Function

'    Public ReadOnly Property DefinedManagableCount() As Int16
'        Get
'            '' returns the number of orders, objective types, token types, unit types, resource types and rule types defined
'            'Dim j As Int16
'            'j = m_ObjectiveTypes.Count + m_UnitTypes.Count + m_TokenTypes.Count + m_ResourceTypes_g.Count + m_RuleTypes_g.Count + m_Orders_g.Count
'            'Return j
'        End Get
'    End Property

'    Public Property MaxPointValueDeployed() As Int32
'        Get
'            Return m_MaxPointValueDeployed
'        End Get
'        Set(ByVal Value As Int32)
'            m_MaxPointValueDeployed = Value
'        End Set
'    End Property

'    Public Property AverageUnitMaxPV() As Int32
'        Get
'            Return m_AverageUnitMaxPV
'        End Get
'        Set(ByVal Value As Int32)
'            m_AverageUnitMaxPV = Value
'        End Set
'    End Property

'    Public Property AverageObjectiveMaxPV() As Int32
'        Get
'            Return m_AverageObjectiveMaxPV
'        End Get
'        Set(ByVal Value As Int32)
'            m_AverageObjectiveMaxPV = Value
'        End Set
'    End Property

'    Public Property ModeratorPassword() As String
'        Get
'            Return m_ModeratorPassword
'        End Get
'        Set(ByVal Value As String)
'            m_ModeratorPassword = Value
'        End Set
'    End Property

'    Public Property Moderator() As ModeratorFlag
'        Get
'            Return m_Moderator
'        End Get
'        Set(ByVal Value As ModeratorFlag)
'            m_Moderator = Value
'        End Set
'    End Property

'    Public Property ReinforcementRange() As Int16
'        Get
'            'HACK: make this return the proper value
'            Return 50
'        End Get
'        Set(ByVal Value As Int16)
'            m_ReinforcementRange = Value
'        End Set
'    End Property
'    Public Property Demo() As Boolean
'        Get
'            Return mvarDemo
'        End Get
'        Set(ByVal Value As Boolean)
'            mvarDemo = Value
'        End Set
'    End Property

'    Public Property GameName() As String
'        Get
'            Return mvarGameName
'        End Get
'        Set(ByVal Value As String)
'            mvarGameName = Value
'        End Set
'    End Property

'    Public Property Version() As String
'        Get
'            Return mvarVersion
'        End Get
'        Set(ByVal Value As String)
'            mvarVersion = Value
'        End Set
'    End Property

'    Public Property TheaterMapFilename() As String
'        Get
'            Return mvarTheaterMapFilename
'        End Get
'        Set(ByVal Value As String)
'            mvarTheaterMapFilename = Value
'        End Set
'    End Property

'    Public Property TheaterMapScale() As String
'        Get
'            Return mvarTheaterMapScale
'        End Get
'        Set(ByVal Value As String)
'            mvarTheaterMapScale = Value
'        End Set
'    End Property

'    Public Property Turn() As Int16
'        Get
'            Return mvarTurn
'        End Get
'        Set(ByVal Value As Int16)
'            mvarTurn = Value
'        End Set
'    End Property

'    Public Property TurnLength() As TurnLength_cgd
'        Get
'            Return mvarTurnLength
'        End Get
'        Set(ByVal Value As TurnLength_cgd)
'            mvarTurnLength = Value
'        End Set
'    End Property

'    Public Property MaxTurns() As Int16
'        Get
'            Return mvarMaxTurns
'        End Get
'        Set(ByVal Value As Int16)
'            mvarMaxTurns = Value
'        End Set
'    End Property

'    Public Property UsesZOC() As Boolean
'        Get
'            Return mvarUsesZOC
'        End Get
'        Set(ByVal Value As Boolean)
'            mvarUsesZOC = Value
'        End Set
'    End Property

'    Public Property SystemValue(ByVal Key As String) As String
'        Get
'            ' returns the item associated with the key or a "NoItem" return value
'            Dim item As Object
'            Try
'                item = mvarSystemValues(Key)
'                If item Is Nothing Then
'                    Return "NoItem"
'                Else
'                    Return item
'                End If
'            Catch
'                Return "NoItem"
'            End Try
'        End Get
'        Set(ByVal Value As String)
'            ' updates or add the value with the associated key
'            Try
'                mvarSystemValues(Key) = Value
'            Catch
'                mvarSystemValues.Add(Key, Value)
'            End Try
'        End Set
'    End Property

'#End Region

'End Class
#End Region


#Region "Factions"

<Serializable()> Public Class Faction14
    '// version 1.4 of the faction class. Improves detection list.
    Inherits Faction

    Private m_Detects As New ChitDetections

    Private Shadows ReadOnly Property HTChitDetection() As Hashtable
        Get
            '// this hides the HTChitDetection CRAP.
            Return Nothing
        End Get
    End Property

    Public Property Detections() As ChitDetections
        Get
            Return m_Detects
        End Get
        Set(ByVal Value As ChitDetections)
            m_Detects = Value
        End Set
    End Property

End Class

<Serializable()> Public Class Factions14
    Inherits CollectionBase

    Default Public Property Item(ByVal index As Integer) As Faction14
        Get
            Return innerlist.Item(index)
        End Get
        Set(ByVal Value As Faction14)
            innerlist.Item(index) = Value
        End Set
    End Property

End Class

#End Region


#Region "New Enums"
<Serializable()> Public Enum movementRate_mr
    hour_mr = 0
    day_mr = 1    '// easy peasy, requires no change for old games.
End Enum
#End Region


#Region "New battlegroup stuff"


Public Interface IChitMember
    ReadOnly Property UnitType() As GroundChitClass_cgd
    Property [Name]() As String
    Property Status() As GroundUnitStatus_cgd
    Property OwningPlayer() As Player
    Property OwningFaction() As Faction
    Property ReadyRules() As Rules2
    Property Resources() As ResourcePool
    Property Location() As Point    '// sure, at one level, we don't use these (chitunitypemember)
    Property PreciseLocation() As PointF
    Property ZOC() As Single
    Property Size() As Single
    Property LOS() As Single
    Property LOSPower() As Single
    Property BattleInvolvedIn() As Battle
    Property CurrentBattlePosture() As BattlePosture_cgd
    Property DetectedThisTurn() As Boolean
    Property BattleResult() As BattleResult_cgd
    Property ChitRules() As ChitRules_c
    Property OOBUnit() As Boolean
    Property CurrentTerrainName() As String
    Property Detected() As Boolean
    Property Icon() As Bitmap
    Property detectionStatus() As Hashtable  '// historical detection status... and game status as matter as a fact. (historical detectionlevelevents)
    Property TimeEnteredBattle() As String
    Property playbackEntries() As HistoricalEntries


    Sub CalculateResourcesAndRules()
    Sub ResetRuleCount()

End Interface


<Serializable()> Public MustInherit Class ChitMember : Implements IChitMember
    Private _name As String
    Private _owningplayer As Player
    Private _status As GroundUnitStatus_cgd
    Private _previousStatus As GroundUnitStatus_cgd
    Private _owningfaction As Faction
    Private _readyrules As New Rules2
    Private _resources As New ResourcePool
    Private _location As Point
    Private _preciseLocation As PointF
    Private _zoc As Single
    Private _los As Single
    Private _size As Single
    Private _lospower As Single
    Private _battleinvolvedin As Battle
    Private _currentbattleposture As BattlePosture_cgd
    Private _battleResult As BattleResult_cgd
    Private _chitrules As New ChitRules_c
    Private _oobUnit As Boolean
    Private _curterrain As String
    Private _icon As Bitmap

    Private _detectedthisturn As Boolean
    Private _detected As Boolean
    Private _detectionStatus As New Hashtable '// deprecated
    Private _detectionLevelThisTurn As ChitDetectionLevel_cdl = ChitDetectionLevel_cdl.Undetected
    Private _timeEnteredBattle As String = ""
    Private _playbackEntries As HistoricalEntries
    <NonSerialized()> Private _detectedthisphase As Boolean
    Private _indicators As Collection
    Private _attributes As Collection

    Public MustOverride ReadOnly Property UnitType() As GroundChitClass_cgd Implements IChitMember.UnitType

    Public Property Indicators() As Collection
        Get
            Return _indicators
        End Get
        Set(ByVal value As Collection)
            _indicators = value
        End Set
    End Property

    Public Property Attributes() As Collection
        Get
            Return _attributes
        End Get
        Set(ByVal value As Collection)
            _attributes = value
        End Set
    End Property

    Public Property detectedThisPhase() As Boolean
        Get
            Return _detectedthisphase
        End Get
        Set(ByVal value As Boolean)
            _detectedthisphase = value
        End Set
    End Property

    Public Property playbackEntries() As HistoricalEntries Implements IChitMember.playbackEntries
        Get
            Return _playbackEntries
        End Get
        Set(ByVal value As HistoricalEntries)
            _playbackEntries = value
        End Set
    End Property

    Public Property TimeEnteredBattle() As String Implements IChitMember.TimeEnteredBattle
        Get
            Return _timeenteredbattle
        End Get
        Set(ByVal value As String)
            _timeenteredbattle = value
        End Set
    End Property

    Public Sub ResetRuleCount() Implements IChitMember.ResetRuleCount
        Try

            For Each ru As Rule In _chitrules
                ru.usesRemaining = 1
            Next

            If UnitType = GroundChitClass_cgd.Battlegroup Then
                Dim bg As BattlegroupChit = DirectCast(Me, BattlegroupChit)

                For Each mem As ChitMember In bg.members
                    mem.ResetRuleCount()
                Next
            End If

        Catch ex As Exception
            HandleException("ChitMember.ResetRuleCount", ex)
        End Try
    End Sub

    Public Property PreciseLocation() As PointF Implements IChitMember.PreciseLocation
        Get
            Return _preciseLocation
        End Get
        Set(ByVal value As PointF)
            _preciseLocation = value
        End Set
    End Property

    Public Property PreviousStatus() As GroundUnitStatus_cgd
        Get
            Return _previousStatus
        End Get
        Set(ByVal value As GroundUnitStatus_cgd)
            _previousStatus = value
        End Set
    End Property

    Public Property HistoricalStatus() As Hashtable Implements IChitMember.detectionStatus
        Get
            Return _detectionStatus
        End Get
        Set(ByVal value As Hashtable)
            _detectionStatus = value
        End Set
    End Property

    Public Property detectionLevelThisTurn() As ChitDetectionLevel_cdl
        Get
            Return _detectionLevelThisTurn
        End Get
        Set(ByVal value As ChitDetectionLevel_cdl)
            _detectionLevelThisTurn = value
        End Set
    End Property

    Public Property globalPhaseDied() As Long
        Get

        End Get
        Set(ByVal value As Long)

        End Set
    End Property

    Public Property icon() As Bitmap Implements IChitMember.Icon
        Get
            Return _icon
        End Get
        Set(ByVal value As Bitmap)
            _icon = value
        End Set
    End Property

    Public Property detected() As Boolean Implements IChitMember.Detected
        Get
            Return _detected
        End Get
        Set(ByVal value As Boolean)
            _detected = value
        End Set
    End Property

    Public Property OOBUnit() As Boolean Implements IChitMember.OOBUnit
        Get
            Return _oobUnit
        End Get
        Set(ByVal value As Boolean)
            _oobUnit = value
        End Set
    End Property

    Public Property chitRules() As ChitRules_c Implements IChitMember.ChitRules
        Get
            Return _chitrules
        End Get
        Set(ByVal value As ChitRules_c)
            _chitrules = value
        End Set
    End Property

    Public Property battleResult() As BattleResult_cgd Implements IChitMember.BattleResult
        Get
            Return _battleResult
        End Get
        Set(ByVal value As BattleResult_cgd)
            _battleResult = value
        End Set
    End Property

    Public Property detectedThisTurn() As Boolean Implements IChitMember.DetectedThisTurn
        Get
            Return _detectedthisturn
        End Get
        Set(ByVal value As Boolean)
            _detectedthisturn = value
        End Set
    End Property

    Public Property currentBattlePosture() As BattlePosture_cgd Implements IChitMember.CurrentBattlePosture
        Get
            Return _currentbattleposture
        End Get
        Set(ByVal value As BattlePosture_cgd)
            _currentbattleposture = value
        End Set
    End Property

    Public Property battleInvolvedIn() As Battle Implements IChitMember.BattleInvolvedIn
        Get
            Return _battleinvolvedin
        End Get
        Set(ByVal value As Battle)

            _battleinvolvedin = value
        End Set
    End Property

    Public Property Name() As String Implements IChitMember.Name
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Property OwningPlayer() As Player Implements IChitMember.OwningPlayer
        Get
            Return _owningplayer
        End Get
        Set(ByVal value As Player)
            _owningplayer = value
        End Set
    End Property

    Public Property Status() As GroundUnitStatus_cgd Implements IChitMember.Status
        Get
            Return _status
        End Get
        Set(ByVal value As GroundUnitStatus_cgd)
            _status = value

            If Me.UnitType = GroundChitClass_cgd.Battlegroup Then
                '// we go down the chain and set them all to the same if DEAD.
                If value = GroundUnitStatus_cgd.Dead Then
                    For Each mem As ChitMember In DirectCast(Me, BattlegroupChit).members
                        mem.Status = value
                    Next
                End If
            End If
        End Set
    End Property

    Public Property OwningFaction() As Faction Implements IChitMember.OwningFaction
        Get
            Return _owningfaction
        End Get
        Set(ByVal value As Faction)
            _owningfaction = value
        End Set
    End Property

    Public Property ReadyRules() As Rules2 Implements IChitMember.ReadyRules
        Get
            Return _readyrules
        End Get
        Set(ByVal value As Rules2)
            _readyrules = value
        End Set
    End Property


    Public Sub CalculateResourcesAndRules() Implements IChitMember.CalculateResourcesAndRules
        '// populates resources and rules based on members
        'TODO: populate resources and rules
    End Sub

    Public Overrides Function ToString() As String
        Return _name
    End Function

    Public Property Location() As System.Drawing.Point Implements IChitMember.Location
        Get
            Return New Point(CInt(_preciseLocation.X), CInt(_preciseLocation.Y))
        End Get
        Set(ByVal value As System.Drawing.Point)
            _preciseLocation.X = value.X
            _preciseLocation.Y = value.Y
        End Set
    End Property

    Public Overridable Property LOS() As Single Implements IChitMember.LOS
        Get
            Return _los
        End Get
        Set(ByVal value As Single)
            _los = value
        End Set
    End Property

    Public Overridable Property LOSPower() As Single Implements IChitMember.LOSPower
        Get
            Return _lospower
        End Get
        Set(ByVal value As Single)
            _lospower = value
        End Set
    End Property

    Public Overridable Property Size() As Single Implements IChitMember.Size
        Get
            Return _size
        End Get
        Set(ByVal value As Single)
            _size = value
        End Set
    End Property

    Public Overridable Property ZOC() As Single Implements IChitMember.ZOC
        Get
            Return _zoc
        End Get
        Set(ByVal value As Single)
            _zoc = value
        End Set
    End Property

    Public Property Resources() As ResourcePool Implements IChitMember.Resources
        Get
            Return _resources
        End Get
        Set(ByVal value As ResourcePool)
            _resources = value
        End Set
    End Property

    Public Property CurrentTerrainName() As String Implements IChitMember.CurrentTerrainName
        Get
            Return _curterrain
        End Get
        Set(ByVal value As String)
            _curterrain = value
        End Set
    End Property
End Class


<Serializable()> Public Class BattlegroupChit
    Inherits ChitMember
    '// this is what is actually drawn on the map...
    Private _overridepointvalue As Single = 0   '// if this is set, it's what's used instead of suggested point value
    Private _currentPointValue As Single
    Private _historicalPosition As New ArrayList
    Private _historicalPosition2 As New Hashtable(50)  '// the "key" is the globalphase number (always goes up)
    Private _deployedPointValue As Single '// this is set each time the group is deployed, or created (by combining BGs)
    Private _waypoints As New SmartWaypoints
    Private _order As String = "Hold"
    Private _movementSpeed As Single
    Private _movementClassID As Integer
    Private _members As New ChitMembers
    Private _mixedMovementClass As Boolean
    Private _availableTransport As Long '// this is AFTER its own units are transported
    Private _readyToBeTransported As Long '// number of poor souls who want to be transported
    Private _moveremaining As Integer
    Private _effectivespeed As Single
    Private _moveaccumulated As Single
    Private _invalidwaypoint As Boolean
    Private _distancetravelled As Single
    Private _effectivereinforcement As Single

    Private _OOBGroup As Boolean = False

    Private _advantages(5) As Advantage

    Public Sub New()
        For i As Integer = 0 To _advantages.GetUpperBound(0)
            _advantages(i) = New Advantage
        Next
    End Sub

    Public Property OOBGroup() As Boolean
        Get
            Return _OOBGroup
        End Get
        Set(ByVal value As Boolean)
            _OOBGroup = value
        End Set
    End Property

    Public Property Advantages() As Advantage()
        Get
            Return _advantages
        End Get
        Set(ByVal value As Advantage())
            _advantages = value
        End Set
    End Property

    Public Property HistoricalPosition2() As Hashtable
        Get
            Return _historicalPosition2
        End Get
        Set(ByVal value As Hashtable)
            _historicalPosition2 = value
        End Set
    End Property

    Public Property overridePointValue() As Single
        Get
            Return _overridepointvalue
        End Get
        Set(ByVal value As Single)
            _overridepointvalue = value
        End Set
    End Property

    Public ReadOnly Property effectiveReinforcement() As Single
        Get
            Return _effectivereinforcement
        End Get
    End Property

    Public Property distanceTravelled() As Single
        Get
            Return _distancetravelled
        End Get
        Set(ByVal value As Single)
            _distancetravelled = value
        End Set
    End Property

    Public Property invalidWaypoint() As Boolean
        Get
            Return _invalidwaypoint
        End Get
        Set(ByVal value As Boolean)
            _invalidwaypoint = value
        End Set
    End Property

    Public Property moveAccumulated() As Single
        Get
            Return _moveaccumulated
        End Get
        Set(ByVal value As Single)
            _moveaccumulated = value
        End Set
    End Property

    Public Property moveRemaining() As Integer
        Get
            Return _moveremaining
        End Get
        Set(ByVal value As Integer)
            _moveremaining = value
        End Set
    End Property

    Public Property effectiveSpeed() As Single
        Get
            Return _effectivespeed
        End Get
        Set(ByVal value As Single)
            _effectivespeed = value
        End Set
    End Property

    Public Property members() As ChitMembers
        Get
            Return _members
        End Get
        Set(ByVal value As ChitMembers)
            _members = value
        End Set
    End Property

    Public Property availableTransport() As Long
        Get
            Return _availableTransport
        End Get
        Set(ByVal value As Long)
            _availableTransport = value
        End Set
    End Property

    Public Property readyToBeTransported() As Long
        Get
            Return _readyToBeTransported
        End Get
        Set(ByVal value As Long)
            _readyToBeTransported = value
        End Set
    End Property

    Public Property movementSpeed() As Single
        Get
            Return _movementSpeed
        End Get
        Set(ByVal value As Single)
            _movementSpeed = value
        End Set
    End Property

    Public Property movementClassID() As Integer
        Get
            Return _movementClassID
        End Get
        Set(ByVal value As Integer)
            _movementClassID = value
        End Set
    End Property

    Public Property mixedMovementClass() As Boolean
        Get
            Return _mixedMovementClass
        End Get
        Set(ByVal value As Boolean)
            _mixedMovementClass = value
        End Set
    End Property

    Public Property deployedpointvalue() As Single
        Get
            Return _deployedPointValue
        End Get
        Set(ByVal value As Single)
            _deployedPointValue = value
        End Set
    End Property

    Public Property waypoints() As SmartWaypoints
        Get
            Return _waypoints
        End Get
        Set(ByVal value As SmartWaypoints)
            _waypoints = value
        End Set
    End Property

    Public Property order() As String
        Get
            Return _order
        End Get
        Set(ByVal value As String)
            _order = value
        End Set
    End Property

    Public Property historicalPosition() As ArrayList
        Get
            Return _historicalPosition
        End Get
        Set(ByVal value As ArrayList)
            _historicalPosition = value
        End Set
    End Property

    Public Property CurrentPV() As Single
        Get
            If _overridepointvalue > 0 Then Return _overridepointvalue
            Return _currentPointValue
        End Get
        Set(ByVal value As Single)
            _currentPointValue = value
        End Set
    End Property

    Public Function RemainingPointValue() As Single
        '// returns the point value of all items, even if they are dead.
        'TODO: remaining pv
    End Function

    Public Overrides ReadOnly Property UnitType() As GroundChitClass_cgd
        Get
            Return GroundChitClass_cgd.Battlegroup
        End Get
    End Property


    Public Sub calculateProperties()
        Try
            CalculateMovement()
            '// now we need to calculate LOS and ZOC and... SIZE and stuff. Yah.
            CalculateLOSSizeZOC()

            CalculateReinforcementRange()

            CalculatePointValue()

            '// calculate RULES!! aya!!
            CalculateRules()
        Catch ex As Exception
            HandleException("BattlegroupChit.calculateProperties", ex)
        End Try

    End Sub

    Private Sub CalculatePointValue()
        Try
            If _overridepointvalue = 0 Then
                CurrentPV = SuggestedPointValue()
            Else
                CurrentPV = _overridepointvalue
            End If
        Catch ex As Exception
            HandleException("CalculatePointValue", ex)
        End Try
    End Sub

    Private Sub CalculateReinforcementRange()
        '// simply the smallest reinforcement range
        Try
            Dim small As Single = 1000

            For Each mem As ChitMember In Me.members
                Dim datone As Single = ReinforcementRange(mem, small)
                If datone < small Then small = datone
            Next

            _effectivereinforcement = small

        Catch ex As Exception
            HandleException("BattlegroupChit.calculateProperties", ex)
            _effectivereinforcement = 0
        End Try
    End Sub

    Private Function ReinforcementRange(ByRef mem As ChitMember, ByVal currentSmallest As Single) As Single
        Try
            Dim smalltime As Single

            If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                For Each omem As ChitMember In DirectCast(mem, BattlegroupChit).members
                    smalltime = 10000
                    smalltime = ReinforcementRange(omem, currentSmallest)
                    If smalltime < currentSmallest Then currentSmallest = smalltime
                Next
            ElseIf mem.UnitType = GroundChitClass_cgd.Unit Then
                If DirectCast(mem, ChitUnitTypeMember).ptrUnitType.ReinforcementRange < currentSmallest Then
                    currentSmallest = DirectCast(mem, ChitUnitTypeMember).ptrUnitType.ReinforcementRange
                End If
            End If

            Return currentSmallest

        Catch ex As Exception
            HandleException("BattlegroupChit.calculateProperties", ex)
            Return 0
        End Try
    End Function

    Public Function SuggestedPointValue() As Single
        Dim mem As IChitMember
        Dim calcPV As Single = 0

        If overridePointValue <> 0 Then Return Me.overridePointValue

        Try
            For Each mem In Me.members
                If Not mem.Status = GroundUnitStatus_cgd.Dead Then
                    If TypeOf mem Is BattlegroupChit Then
                        '// we calculate this guys PV first.
                        DirectCast(mem, BattlegroupChit).calculateProperties()
                        calcPV += DirectCast(mem, BattlegroupChit).SuggestedPointValue
                    Else
                        '// its a unit, either use override pv or ptrunittype suggested
                        If DirectCast(mem, ChitUnitTypeMember).OverridePointValue <> 0 Then
                            calcPV += DirectCast(mem, ChitUnitTypeMember).OverridePointValue
                        Else
                            calcPV += DirectCast(mem, ChitUnitTypeMember).ptrUnitType.SuggestedPointValue
                        End If

                        '// add elements?
                        If DirectCast(mem, ChitUnitTypeMember).elements Is Nothing Then DirectCast(mem, ChitUnitTypeMember).elements = New GroupableElements
                        For Each el As GroupableElement In DirectCast(mem, ChitUnitTypeMember).elements
                            calcPV += (el.ElementBaseCost * el.Count)
                        Next
                    End If
                End If
            Next
        Catch ex As Exception
            HandleException("BattlegroupChit.SuggestedPointValue", ex)
        End Try

        Return calcPV
    End Function

    Private Sub CalculateMovement()
        '// this is movement speed and movement class ID
        Try
            Dim moveClassBucket As New Hashtable
            Dim mem As IChitMember
            Dim slowMove As Single = 25000.0#
            Dim trans, transNeeded As Long
            '// for now, if everything CAN be transported, it automatically is, otherwise, we just go with the slowest
            '// i would like to do GROUP based tranporting as priority
            Dim allTransGood As Boolean

            TransCap(trans, transNeeded) '// transneeded might not be useful. Lets take it away...

            If trans >= transNeeded Then allTransGood = True

            For Each mem In members

                If TypeOf mem Is BattlegroupChit Then
                    '// calculate the properties of the "sub" battlegroup
                    'DirectCast(mem, BattlegroupChit).calculateProperties()   '// moved into transcap
                    '// move class 
                    If Not moveClassBucket.ContainsKey(DirectCast(mem, BattlegroupChit).movementClassID) Then moveClassBucket.Add(DirectCast(mem, BattlegroupChit).movementClassID, DirectCast(mem, BattlegroupChit).movementClassID)
                    '// speed check
                    If DirectCast(mem, BattlegroupChit).movementSpeed < slowMove Then
                        slowMove = DirectCast(mem, BattlegroupChit).movementSpeed
                    End If
                Else
                    '// if we can transport, this guy doesn't add anything (AND if we are alltransgood)
                    '// if this item can be transported, and we have enough capacity to transport, we're good, and can ignore its movement stuff
                    Dim checkVals As Boolean = True

                    If DirectCast(mem, ChitUnitTypeMember).ptrUnitType.CanBeTransported = True Then
                        '// if we have a good alltrans, then we can ignore otherwise, use its values.
                        If allTransGood = True Then checkVals = False
                    End If

                    If checkVals = True Then
                        '// this unittype can't be transported, or there is not enough room
                        '// move class
                        If Not moveClassBucket.ContainsKey(DirectCast(mem, ChitUnitTypeMember).ptrUnitType.MovementClassID) Then
                            moveClassBucket.Add(DirectCast(mem, ChitUnitTypeMember).ptrUnitType.MovementClassID, DirectCast(mem, ChitUnitTypeMember).ptrUnitType.MovementClassID)
                        End If
                        '// speed check
                        If DirectCast(mem, ChitUnitTypeMember).ptrUnitType.MovementSpeed < slowMove Then
                            slowMove = DirectCast(mem, ChitUnitTypeMember).ptrUnitType.MovementSpeed
                        End If
                    End If

                End If
            Next

            '// if we have more than one, we're mixed. Plain and simple.
            If moveClassBucket.Count > 1 Then
                '// we're mixed.
                _mixedMovementClass = True
                _movementClassID = 8
            ElseIf moveClassBucket.Count = 1 Then
                Dim skey As String
                For Each skey In moveClassBucket.Keys
                    _movementClassID = skey 'moveClassBucket.Item(skey)
                Next
            Else
                '// we can use the first member's  classid
                '_mixedMovementClass = False
                'If members.Count > 0 Then
                '    If TypeOf Me.members.item(0) Is BattlegroupChit Then
                '        _movementClassID = DirectCast(members.item(0), BattlegroupChit).movementClassID
                '    Else
                '        _movementClassID = DirectCast(members.item(0), ChitUnitTypeMember).ptrUnitType.MovementClassID
                '    End If
                'Else
                '    '// there are no membas. ... so... then what?
                _movementClassID = 0    '// i guess
                'End If

            End If

            If slowMove = 25000 Then slowMove = 0
            movementSpeed = slowMove

        Catch ex As Exception
            HandleException("BattlegroupChit.CalculateMovement", ex)
        End Try
    End Sub

    Private Sub TransCap(ByRef maxCap As Integer, ByRef canBe As Integer)
        '// maxcap is the total, canbe is how many would "like" transporting, and extraavailable is how much is left after all transporting.
        Dim tcap, tcan As Long

        Dim mem As IChitMember
        For Each mem In members
            If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                '// calculate here! :D
                DirectCast(mem, BattlegroupChit).calculateProperties()
                tcap += DirectCast(mem, BattlegroupChit).availableTransport
                tcan += DirectCast(mem, BattlegroupChit).readyToBeTransported
            Else
                tcap += DirectCast(mem, ChitUnitTypeMember).ptrUnitType.TransportCapacity
                tcan += DirectCast(mem, ChitUnitTypeMember).ptrUnitType.TransportCost
            End If
        Next

        maxCap = tcap
        canBe = tcan

        '// set our available, and readyto properties
        availableTransport = maxCap
        readyToBeTransported = tcan

    End Sub

    <Browsable(False)> Private Sub CalculateLOSSizeZOC()
        Try
            If Me.members.Count = 0 Then Exit Sub
            '// we calculate this every turn so nothing funny happens. No sneaking data through or whatever.
            Dim bestlosRange As Single
            Dim bestlosPower As Single
            Dim bestzocRange As Single
            Dim bUsesZOC As Boolean
            Dim bonusLOSArea As Integer = 0
            Dim bonusZOCArea As Integer = 0

            Me.Size = 0

            '// first pass is to deal with all battlegroups
            For Each mem As ChitMember In Me.members
                If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                    DirectCast(mem, BattlegroupChit).CalculateLOSSizeZOC()
                End If
            Next

            For Each mem As ChitMember In Me.members
                If mem.UnitType = GroundChitClass_cgd.Unit Then

                    Dim unitt As UnitType = DirectCast(mem, ChitUnitTypeMember).ptrUnitType
                    Me.Size += unitt.Size

                    If unitt.UsesZOC Then
                        If unitt.ZOCRange > bestzocRange Then
                            bestzocRange = unitt.ZOCRange
                        Else
                            bonusZOCArea += Math.PI * (unitt.ZOCRange * unitt.ZOCRange) * 0.05
                        End If
                        bUsesZOC = True
                    End If

                    If unitt.LOS > bestlosRange Then
                        bestlosRange = unitt.LOS
                    Else
                        bonusLOSArea += Math.PI * (unitt.LOS * unitt.LOS) * 0.05
                    End If

                    If unitt.LOSPower > bestlosPower Then
                        bestlosPower = unitt.LOSPower
                    End If

                Else
                    '// battlegroup
                    Me.Size += mem.Size

                    If mem.ZOC > 0 Then
                        If mem.ZOC > bestzocRange Then
                            bestzocRange = mem.ZOC
                        Else
                            '// we give a 5% ZOC bonus area
                            bonusZOCArea += Math.PI * (mem.ZOC * mem.ZOC) * 0.05
                        End If
                        bUsesZOC = True
                    End If

                    If mem.LOS > bestlosRange Then
                        bestlosRange = mem.LOS
                    Else
                        '// give the bonusLOSArea
                        bonusLOSArea += Math.PI * (mem.LOS * mem.LOS) * 0.05
                    End If

                    If mem.LOSPower > bestlosPower Then
                        bestlosPower = mem.LOSPower
                    End If
                End If

            Next

            '// put the properties in
            Me.LOS = bestlosRange
            Me.LOSPower = bestlosPower
            Me.ZOC = bestzocRange

            '// add bonus area
            If bonusLOSArea > 0 Then
                Dim oldArea As Long = Math.PI * (Me.LOS * Me.LOS)
                Dim newArea As Long = oldArea + bonusLOSArea
                Dim newR As Long = RadiusFromArea(newArea)
                Me.LOS = CInt(newR)
            End If

        Catch ex As Exception
            HandleException("BattlegroupChit.CalculateLOSSizeZOC", ex)
        End Try
    End Sub

    Private Function RadiusFromArea(ByVal area As Single) As Single
        Dim r As Single
        r = Math.Sqrt(area / 3.14)
        Return r
    End Function

    Private Sub CalculateRules()
        Try
            chitRules.Clear()

            '// add my level rules
            For Each mem As ChitMember In Me.members
                For Each ru As Rule In mem.chitRules
                    chitRules.add(ru)
                Next
            Next

        Catch ex As Exception

        End Try
    End Sub

End Class

<Serializable()> Public Class ChitTokenTypeMember
    Inherits ChitMember

    Private _ptrTokenType As TokenType
    Private _isFlipped As Boolean = False

    Public Overrides ReadOnly Property UnitType() As GroundChitClass_cgd
        Get
            Return GroundChitClass_cgd.Token
        End Get
    End Property

    Public Property isFlipped() As Boolean
        Get
            Return _isFlipped
        End Get
        Set(ByVal value As Boolean)
            _isFlipped = value
        End Set
    End Property

    Public Property ptrTokenType() As TokenType
        Get
            Return _ptrTokenType
        End Get
        Set(ByVal value As TokenType)
            _ptrTokenType = value
        End Set
    End Property

    Public Function PointValue() As Single
        If _isFlipped Then
            Return _ptrTokenType.FlippedProperties.PointValue
        Else
            Return _ptrTokenType.FrontProperties.PointValue
        End If
    End Function
End Class

<Serializable()> Public Class ChitUnitTypeMember
    Inherits ChitMember

    Private _ptrunitType As UnitType
    Private _elements As New GroupableElements
    Private _overridePointValue As Single


    Public Property OverridePointValue() As Single
        Get
            Return _overridePointValue
        End Get
        Set(ByVal value As Single)
            _overridePointValue = value
        End Set
    End Property

    Public Property elements() As GroupableElements
        Get
            Return _elements
        End Get
        Set(ByVal value As GroupableElements)
            _elements = value
        End Set
    End Property

    Public Property ptrUnitType() As UnitType
        Get
            Return _ptrunitType
        End Get
        Set(ByVal value As UnitType)
            _ptrunitType = value
            If Not value Is Nothing Then
                '// we'll overwrite the name. It can be changed later by the player.
                MyBase.Name = _ptrunitType.Name
            End If
        End Set
    End Property

    Public Overrides ReadOnly Property UnitType() As GroundChitClass_cgd
        Get
            Return GroundChitClass_cgd.Unit
        End Get
    End Property
End Class


<Serializable()> Public Class ChitMembers : Inherits CollectionBase

    Default Public Property item(ByVal index As Integer) As IChitMember
        Get
            Return InnerList.Item(index)
        End Get
        Set(ByVal value As IChitMember)
            InnerList.Item(index) = value
        End Set
    End Property

    Public Sub add(ByVal value As IChitMember)
        InnerList.Add(value)
    End Sub

    Public Sub remove(ByVal obj As IChitMember)
        InnerList.Remove(obj)
    End Sub

    Public Function contains(ByRef obj As Object) As Boolean
        For Each thing As Object In InnerList
            If thing.Equals(obj) Then Return True
        Next

        Return False

    End Function

End Class


<Serializable()> Public Class InstallationChit
    Inherits ChitMember

    Private _ptrInstallation As ObjectiveType
    Private _Resources As ResourcePool

    <Browsable(False)> Public Property ptrInstallation() As ObjectiveType
        Get
            Return _ptrInstallation
        End Get
        Set(ByVal value As ObjectiveType)
            _ptrInstallation = value
        End Set
    End Property

    Public Property existingResources() As ResourcePool
        Get
            Return _Resources
        End Get
        Set(ByVal value As ResourcePool)
            _Resources = value
        End Set
    End Property

    Public Overrides ReadOnly Property UnitType() As GroundChitClass_cgd
        Get
            Return GroundChitClass_cgd.Objective
        End Get
    End Property

    Public Overrides Property LOS() As Single
        Get
            Return _ptrInstallation.LOS
        End Get
        Set(ByVal value As Single)

        End Set
    End Property

    Public Overrides Property Size() As Single
        Get
            Return _ptrInstallation.Size
        End Get
        Set(ByVal value As Single)

        End Set
    End Property

    Public Overrides Property ZOC() As Single
        Get
            Return _ptrInstallation.ZOCRange
        End Get
        Set(ByVal value As Single)

        End Set
    End Property

    Public Overrides Property LOSPower() As Single
        Get
            Return _ptrInstallation.LOSPower
        End Get
        Set(ByVal value As Single)

        End Set
    End Property

    Public Sub GenerateResources()
        Try
            For Each poo As ResourcePoolItem In Me.Resources
                poo.localAmount += poo.accrueAmount
                If poo.localAmount > poo.maxAmount Then
                    poo.localAmount = poo.maxAmount
                End If

                '// special case if this is a deployment point resource :D
                If poo.localAmount = poo.maxAmount Then
                    If poo.resourceTypeptr.ResourceName = "Deployment Point" Then
                        OwningFaction.FactionTotalPoints += poo.localAmount
                        poo.localAmount = 0
                    End If
                End If
            Next
        Catch ex As Exception
            HandleException("InstallationChit.GenerateResources", ex)
        End Try
    End Sub

End Class

#End Region


#Region "Extension Objects"
'//these are objects used for other games. For instance, it can be used in war pigs.

Public Interface ICampaignerExtensionObject
    Property Name() As String
    Property TreeDisplay() As TreeNode  '// used as representation in a tree node, like in "selected chit"
    Property Description() As String
    Property CDisplay() As Boolean '// if this item should be displayed in Campaigner


End Interface


<Serializable()> Public Class CampaignerExtensionObjects : Inherits CollectionBase

    Default Public Property item(ByVal index As Integer) As ICampaignerExtensionObject
        Get
            Return InnerList.Item(index)
        End Get
        Set(ByVal value As ICampaignerExtensionObject)
            InnerList.Item(index) = value
        End Set
    End Property

    Public Sub add(ByVal value As ICampaignerExtensionObject)
        InnerList.Add(value)
    End Sub

    Public Sub remove(ByVal obj As ICampaignerExtensionObject)
        InnerList.Remove(obj)
    End Sub

End Class


#End Region


<Serializable()> Public Class AirUnit
    '// air units can only detect ground units with a "?", never higher.
    '// turn does not stop when an air unit detects a ground unit or vice versa

    '// new core rule for landing zones... maybe three types?

End Class

<Serializable()> Public Class ResourcePoolItem

    Private _resourceType As ResourceType
    Private _localAmount As Integer
    Private _maxAmount As Integer
    Private _accrueAmount As Integer

    Public Property accrueAmount() As Integer
        Get
            Return _accrueAmount
        End Get
        Set(ByVal value As Integer)
            _accrueAmount = value
        End Set
    End Property

    Public Property maxAmount() As Integer
        Get
            Return _maxAmount
        End Get
        Set(ByVal value As Integer)
            _maxAmount = value
        End Set
    End Property

    Public Property resourceTypeptr() As ResourceType
        Get
            Return _resourceType
        End Get
        Set(ByVal value As ResourceType)
            _resourceType = value
        End Set
    End Property

    Public Property localAmount() As Integer
        Get
            Return _localAmount
        End Get
        Set(ByVal value As Integer)
            _localAmount = value
            If _localAmount > _maxAmount Then _localAmount = _maxAmount
        End Set
    End Property

End Class

<Serializable()> Public Class ResourcePool : Inherits CollectionBase

    Default Public Property item(ByVal index As Integer) As ResourcePoolItem
        Get
            Return InnerList.Item(index)
        End Get
        Set(ByVal value As ResourcePoolItem)
            InnerList.Item(index) = value
        End Set
    End Property

    Public Sub add(ByVal value As ResourcePoolItem)
        InnerList.Add(value)
    End Sub

    Public Sub remove(ByVal obj As ResourcePoolItem)
        InnerList.Remove(obj)
    End Sub

End Class


<Serializable()> Public Class HistoricalDetectionStatusEntry
    Private _detStat As ChitDetectionLevel_cdl
    Private _location As Point

    Public Property detectionStatus() As ChitDetectionLevel_cdl
        Get
            Return _detStat
        End Get
        Set(ByVal value As ChitDetectionLevel_cdl)
            _detStat = value
        End Set
    End Property

    Public Property location() As Point
        Get
            Return _location
        End Get
        Set(ByVal value As Point)
            _location = value
        End Set
    End Property

End Class


<Serializable()> Public Class HistoricalEntry

    Private _detectionStatus As Byte
    Private _unitStatus As Byte
    Private _x As Short
    Private _y As Short

    Public Property unitStatus() As GroundUnitStatus_cgd
        Get
            Return CType(_unitStatus, GroundUnitStatus_cgd)
        End Get
        Set(ByVal value As GroundUnitStatus_cgd)
            _unitStatus = CByte(value)
        End Set
    End Property

    Public Property detectionStatus() As ChitDetectionLevel_cdl
        Get
            Return CType(_detectionStatus, ChitDetectionLevel_cdl)
        End Get
        Set(ByVal value As ChitDetectionLevel_cdl)
            _detectionStatus = CByte(value)
        End Set
    End Property

    Public Property location() As Point
        Get
            Return New Point(_x, _y)
        End Get
        Set(ByVal value As Point)
            _x = CShort(value.X)
            _y = CShort(value.Y)
        End Set
    End Property

End Class


<Serializable()> Public Class HistoricalEntries
    'Inherits Hashtable
    Private _mybase As New Hashtable


    Default Public Shadows Property item(ByVal key As String) As HistoricalEntry
        Get
            Return _mybase.Item(key)
        End Get
        Set(ByVal value As HistoricalEntry)
            _mybase.Item(key) = value
        End Set
    End Property

    Public Shadows Sub add(ByVal key As String, ByRef value As HistoricalEntry)
        _mybase.Add(key, value)
    End Sub

    Public Shadows Sub remove(ByVal key As String)
        _mybase.Remove(key)
    End Sub

End Class


